//
//  FSPersonViewController.m
//  Trade
//
//  Created by 刘沿 on 16/4/1.
//  Copyright © 2016年 刘沿. All rights reserved.
/*
 待办文件 已办文件 电子公告 最新收文 最新发文 邮件 通讯录
 
 
 */

#import "FSPersonViewController.h"

@interface FSPersonViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>

@end

@implementation FSPersonViewController

static NSString * const reuseIdentifier = @"Cell";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UICollectionViewFlowLayout *Layout = [[UICollectionViewFlowLayout alloc] init];
    
    Layout.itemSize = CGSizeMake(100, 100);
    
    Layout.minimumLineSpacing = 30;
    
    Layout.sectionInset = UIEdgeInsetsMake(20, 20, 0, 20);
    
    UICollectionView *collec = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:Layout];
    
    collec.dataSource = self;
    collec.delegate = self;
    
//    [collec registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];

    [collec registerNib:[UINib nibWithNibName:@"FSPersonCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:reuseIdentifier];
    
    collec.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:collec];
    
    
//导航栏添加一个退出按钮
    UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:@"退出" style:UIBarButtonItemStylePlain target:self action:@selector(cancel)];
    
    self.navigationItem.rightBarButtonItem = btn;
    
    
}

- (void)cancel{
    UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:nil message:@"是否退出登录" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alertView show];
}

//按钮点击后调用，视图自动消失后返回，退出按钮点击后，点击取消确定会来到这个方法
//- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
//    
//    //    确定按钮
//    if (buttonIndex == 1) {
////        OALoginViewController * loginVC = (OALoginViewController*) [self.storyboard instantiateViewControllerWithIdentifier:@"LoginVC"];
////        UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:loginVC];
////        self.view.window.rootViewController = nav;
//        
//        FSLoginViewController *loginVC = [self.storyboard instantiateViewControllerWithIdentifier:@""];
//        
//        
//        
//    }
//}



- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return 7;

}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    FSPersonCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
//    cell.backgroundColor = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0  blue:arc4random_uniform(255)/255.0  alpha:1];
    
    switch (indexPath.item) {
        case 0:
            
            cell.imageName.image = [UIImage imageNamed:@"待办事项-72x72"];
            cell.LabelText.text = @"待办文件";
            
            break;
            
        case 1:
            
            cell.imageName.image = [UIImage imageNamed:@"已办事项-72x72"];
            cell.LabelText.text = @"已办文件";
            
            break;
            
        case 2:
            cell.imageName.image = [UIImage imageNamed:@"通知通告-2倍切图"];
            cell.LabelText.text = @"电子公告";
            break;
            
        case 3:
            cell.imageName.image = [UIImage imageNamed:@"最新收文-72x72"];
            cell.LabelText.text = @"最新收文";
            break;
            
        case 4:
            cell.imageName.image = [UIImage imageNamed:@"最新发文-72x72"];
            cell.LabelText.text = @"最新发文";
            break;
            
        case 5:
            cell.imageName.image = [UIImage imageNamed:@"电子邮件-72x72"];
            cell.LabelText.text = @"邮件";
            break;
            
        case 6:
            cell.imageName.image = [UIImage imageNamed:@"通讯录-72x72"];
            cell.LabelText.text = @"通讯录";
            break;
     
        default:
            break;
    }
    
    return cell;

}

#pragma mark-------代理方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
 
        switch (indexPath.item) {
            case 0:{
//待办工作
        FSupCommingWorkController *upVC = [self.storyboard instantiateViewControllerWithIdentifier:@"upVC"];
                
        [self.navigationController pushViewController:upVC animated:YES];
        }
            break;
       
//已办工作
        case 1:
            {
        FSToDoingWorkController *todoVC = [self.storyboard instantiateViewControllerWithIdentifier:@"toVC"];
            
        [self.navigationController pushViewController:todoVC animated:YES];
            }
                
            break;
        default:
            break;
    }


}


@end
